package com.muy.ahc.task.copy;

import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.Copy;

import java.io.File;


public class CopyArthasbinToPluginTask extends Copy {

    public static final String NAME = "copyArthasbinToArthasbinTask";
    public static final String TEST_NAME = "copyArthasbinToArthasbinTestTask";

    public static final String TARGET_SUBFOLDER = "arthasbin";

    private static final String ARTHAS_BIN_PATH = "idea-sandbox/plugins";

    private static final String TEST_ARTHAS_BIN_PATH = "idea-sandbox/plugins-test";

    public CopyArthasbinToPluginTask() {
        setGroup("intellij");
        configureTask(false);
//        final CopyAgentWrapToJvmSandboxTask gatherTask = (CopyAgentWrapToJvmSandboxTask) getProject().getTasks().getByName(CopyAgentWrapToJvmSandboxTask.NAME);
//        dependsOn(gatherTask);
        from(new File("arthasbin"));
    }


    private void configureTask(final boolean test) {
        String sandbox = (test ? TEST_ARTHAS_BIN_PATH : ARTHAS_BIN_PATH);
        setDescription("Adds the arthasbin directory to " + sandbox);
        into(new File(getProject().getBuildDir(), sandbox + "/ArthasHttpConsole/" + TARGET_SUBFOLDER));
    }


    public void setTest() {
        configureTask(true);
        final Project project = getProject();
        project.getTasks().getByName(JavaPlugin.TEST_TASK_NAME).dependsOn(this);
    }
}
